1 module features.hipreme_engine; 2 import commons; 3 import feature; 4 import features.git; 5 6 private immutable requiredFiles = ["dub.json", "hipreme_engine.sln", "HipremeEngine.code-workspace"]; 7 8 private bool isValidEnginePath(string path) 9 { 10 return filesExists(path, requiredFiles); 11 } 12 private bool isRunningFromDubRun(string enginePath) 13 { 14 return executeShell("cd \""~enginePath~"\" && git status").status != 0; 15 } 16 17 bool installHipremeEngine(ref Terminal t, ref RealTimeConsoleInput input, TargetVersion ver, Download[] contents) 18 { 19 import std.array:replace; 20 string hipremeEnginePath; 21 if("HIPREME_ENGINE" in environment) 22 { 23 hipremeEnginePath = environment["HIPREME_ENGINE"]; 24 if(hipremeEnginePath[0] == '"' && hipremeEnginePath[$-1] == '"') 25 hipremeEnginePath = hipremeEnginePath[1..$-1]; 26 t.writelnHighlighted("Using existing environment variable 'HIPREME_ENGINE' for hipremeEnginePath"); 27 } 28 else 29 { 30 ///Check for existing Hipreme Engine 31 import core.runtime; 32 import std.algorithm:find; 33 34 auto possibleResult = 35 [ 36 ".", 37 buildNormalizedPath(std.file.getcwd(), "..", ".."), 38 dirName(Runtime.args[0]), 39 buildNormalizedPath(dirName(Runtime.args[0]), "..", ".."), 40 ].find!((string dir) => isValidEnginePath(dir)); 41 if(possibleResult.length) 42 hipremeEnginePath = possibleResult[0]; 43 44 if(hipremeEnginePath.length) 45 { 46 if(isRunningFromDubRun(hipremeEnginePath)) 47 { 48 t.writelnHighlighted( 49 "HipremeEngine is present, but dub does not support git repositories containing submodules.\n", 50 "\tHipremeEngine needs to be cloned."); 51 goto clone; 52 } 53 t.writelnHighlighted("Using engine path found at directory '"~hipremeEnginePath~"'"); 54 } 55 else 56 { 57 clone: bool canClone = pollForExecutionPermission(t, input, "HipremeEngine path wasn't found in configs. Do you want to clone the engine?"); 58 if(canClone) 59 { 60 if(t.wait(spawnShell(getGitExec~" clone "~hipremeEngineRepo)) != 0) 61 { 62 t.writelnError("Could not clone HipremeEngine on repo ", hipremeEngineRepo); 63 return false; 64 } 65 hipremeEnginePath = buildNormalizedPath(std.file.getcwd(), "HipremeEngine"); 66 } 67 else 68 { 69 hipremeEnginePath = getValidPath(t, "HipremeEngine Path: "); 70 if(!isValidEnginePath(hipremeEnginePath)) 71 { 72 import std.string:join; 73 t.writelnHighlighted("Path is not valid. HipremeEngine path should have: \n\t"~requiredFiles.join("\n\t")); 74 goto clone; 75 } 76 } 77 } 78 } 79 configs["hipremeEnginePath"] = hipremeEnginePath; 80 updateConfigFile(); 81 submoduleLoader.execute(t, input); 82 return true; 83 } 84 85 86 Feature HipremeEngineFeature; 87 void initialize() 88 { 89 HipremeEngineFeature = Feature( 90 "Hipreme Engine", 91 "The engine for D game development", 92 ExistenceChecker(["hipremeEnginePath"]), 93 Installation(null, toDelegate(&installHipremeEngine)), 94 (ref Terminal, string where){environment["HIPREME_ENGINE"] = where;}, 95 VersionRange(), 96 ); 97 } 98 void start() 99 { 100 HipremeEngineFeature.dependencies = [&GitFeature]; 101 }